package com.ruoyi.mentor.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.mentor.domain.Examine;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mentor.vo.ExamineVo;
import com.ruoyi.mentor.bo.ExamineQueryBo;
import com.ruoyi.mentor.bo.ExamineAddBo;
import com.ruoyi.mentor.bo.ExamineEditBo;
import com.ruoyi.mentor.service.IExamineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 审核信息Controller
 *
 * @author LH
 * @date 2021-05-22
 */
@Api(value = "审核信息控制器", tags = {"审核信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mentor/examine")
public class ExamineController extends BaseController {

    private final IExamineService iExamineService;

    /**
     * 查询审核信息列表
     */
    @ApiOperation("查询审核信息列表")
    @PreAuthorize("@ss.hasPermi('mentor:examine:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamineVo> list(@Validated ExamineQueryBo bo) {
        return iExamineService.queryPageList(bo);
    }

    /**
     * 导出审核信息列表
     */
    @ApiOperation("导出审核信息列表")
    @PreAuthorize("@ss.hasPermi('mentor:examine:export')")
    @Log(title = "审核信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(@Validated ExamineQueryBo bo) {
        List<ExamineVo> list = iExamineService.queryList(bo);
        ExcelUtil<ExamineVo> util = new ExcelUtil<ExamineVo>(ExamineVo.class);
        return util.exportExcel(list, "审核信息");
    }

    /**
     * 获取审核信息详细信息
     */
    @ApiOperation("获取审核信息详细信息")
    @PreAuthorize("@ss.hasPermi('mentor:examine:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iExamineService.queryById(id));
    }

    /**
     * 新增审核信息
     */
    @ApiOperation("新增审核信息")
    @PreAuthorize("@ss.hasPermi('mentor:examine:add')")
    @Log(title = "审核信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult add(@Validated @RequestBody ExamineAddBo bo) {
        return toAjax(iExamineService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改审核信息
     */
    @ApiOperation("修改审核信息")
    @PreAuthorize("@ss.hasPermi('mentor:examine:edit')")
    @Log(title = "审核信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult edit(@Validated @RequestBody ExamineEditBo bo) {
        return toAjax(iExamineService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除审核信息
     */
    @ApiOperation("删除审核信息")
    @PreAuthorize("@ss.hasPermi('mentor:examine:remove')")
    @Log(title = "审核信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iExamineService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }


    /**
     * 获取审核信息
     */
    @ApiOperation("获取审核信息")
    @GetMapping("/getExamineMsg")
    public AjaxResult getExamineMsg(@RequestParam("type")Integer type,@RequestParam("id")Long id) {
        Examine examine = iExamineService.getExamineMsg(type,id);
        return AjaxResult.success(examine);
    }


}
